package com.dong.tools;

import java.io.BufferedWriter;
import java.io.File;
import java.io.PrintWriter;
import jxl.Cell;
import jxl.Hyperlink;
import jxl.Sheet;
import jxl.Workbook;

public class GetDataFromExcel {

	/*
	 * 1.把下面的title的内容替换成具体的内容
	 * 2.把经过处理的excel放到/home/dong/aaa.xls里
	 * 	2.1 A列放 手机名称android版本
	 * 	2.2 B列放 下载日志（带链接）
	 * 3.在相同目录下得到data文件
	 * */
	public static void main(String[] args) {
		String title = "内容";
		String path = "/home/dong/";
		
		StringBuffer sb = new StringBuffer();
		try {
			File f = new File(path+"aaa.xls");
			Workbook rwb = Workbook.getWorkbook(f);
			Sheet[] sheet = rwb.getSheets();
			System.out.println(sheet[0].getName());
			
			Sheet rs = rwb.getSheet(0);   

			Hyperlink[] links = rs.getHyperlinks();
			
			for( int s=0; s<rs.getRows(); s++ ){
				Cell[] cells = rs.getRow(s);
				String tmp = title +"\t"+ links[s].getURL().toString()+"\t"+cells[0].getContents()+"\n";
				System.out.println(tmp);
				sb.append(tmp);
			}
			
			File out_file = new File(path + "data");
			BufferedWriter bf=new BufferedWriter(new PrintWriter(out_file));
			bf.write("");
			bf.write(sb.toString());
			bf.flush();
			bf.close();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}


}
